package cn.zbmao.web.config;

import cn.zbmao.web.bean.News;
import cn.zbmao.web.bean.User;
import cn.zbmao.web.controller.HomeController;
import cn.zbmao.web.controller.LoginController;
import cn.zbmao.web.controller.NewsController;
import cn.zbmao.web.controller.SearchController;
import cn.zbmao.web.controller.user.*;
import cn.zbmao.web.interceptor.MyIntercepter;
import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;

public class TenderConfig extends JFinalConfig {
	public static String objectUrl = null;

	@Override
	public void configConstant(Constants me) {
		// ����������Ҫ���ã�������getProperty(...)��ȡֵ
		loadPropertyFile("DB_config.txt");
		me.setDevMode(getPropertyToBoolean("devMode", true));
//		me.setDevMode(false);
		objectUrl=getProperty("objectUrl");
		me.setError404View("/home/404.html");
		me.setError500View("/home/500.html");
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler());
	}

    /**
     * 添加拦截器
     * @param me
     */
	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new MyIntercepter());
		me.add(new SessionInViewInterceptor());
	}

	@Override
	public void configPlugin(Plugins me) {
		//缓存
		//me.add(new EhCachePlugin());
		// ����C3p0��ݿ����ӳز��
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		c3p0Plugin.setInitialPoolSize(getPropertyToInt("InitialPoolSize"));
		c3p0Plugin.setMinPoolSize(getPropertyToInt("MinPoolSize"));
		c3p0Plugin.setMaxPoolSize(getPropertyToInt("MaxPoolSize"));
		c3p0Plugin.setAcquireIncrement(getPropertyToInt("AcquireIncrement"));
		
		
		me.add(c3p0Plugin);
		// ����ActiveRecord���
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		
		//debug
		arp.setShowSql(getPropertyToBoolean("ShowSql"));
		
		arp.addMapping("user", User.class);
		arp.addMapping("tender_news_info", News.class);

	}

    /**
     * 接收请求后，转到指定的控制器
     * @param me
     */
	@Override
	public void configRoute(Routes me) {
		me.add("/", SearchController.class);
		me.add("/login", LoginController.class);
		me.add("/oauth",AuthController.class);
		me.add("/home",HomeController.class);
		me.add("/keyword",KeywordController.class);
		me.add("/user_url",UserUrlController.class);
		me.add("/user_district",UserDistrictController.class);
		me.add("/user_qualification",QualificationController.class);
		me.add("/news",NewsController.class);
		me.add("/signup",SignupController.class);
		me.add("/search",SearchController.class);
		me.add("/resetpwd",ResetPwdController.class);
        //用户验证
        me.add("/account/ajax", AccountAjaxController.class);
	}
	
	/**
	 * test run
	 * @param args
	 */
	public static void main(String[] args) {
		JFinal.start("WebRoot", 8080, "/", 5);
	}
}
